using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DALVPPPayment
/// </summary>
public class DALVPPPayment
{

    /// <summary>
    /// Get one VPP Payment
    /// </summary>
    /// <param name="deliverableID">DeliverableID of VPP Payment</param>
    /// <returns>VPPPayment</returns>
    public static VPPPayment GetOneVPPPaymet(int deliverableID)
    {
        return DAL.GetDataItem<VPPPayment>(SQL.GetOneVPPPayment, new string[] { "@DeliverableID" }, new object[] { deliverableID });
    }

    /// <summary>
    /// Get all VPP Payments
    /// </summary>
    /// <returns>List of VPP Payments</returns>
    public static List<VPPPayment> GetAllVPPPayments()
    {
        return DAL.GetDataItems<VPPPayment>(SQL.GetAllVPPPayment, null, null);
    }

    /// <summary>
    /// Search VPP Payment by deliverableID
    /// </summary>
    /// <param name="deliverableID">DeliverableID to search</param>
    /// <returns>List of VPP Payments</returns>
    public static List<VPPPayment> SearchVPPPaymentByDeliverableID(int deliverableID)
    {
        return DAL.GetDataItems<VPPPayment>(SQL.SearchVPPPaymentByDeliverableID, new string[] { "@DeliverableID" }, new object[] { deliverableID });
    }

    /// <summary>
    /// Search VPP Payment by FullName of customer
    /// </summary>
    /// <param name="fullName">FullNam of customer to search</param>
    /// <returns>List of VPP Payments</returns>
    public static List<VPPPayment> SearchVPPPaymentByFullName(string fullName)
    {
        return DAL.GetDataItems<VPPPayment>(SQL.SearchVPPPaymentByFullName, new string[] { "@FullName" }, new object[] { fullName });
    }

    /// <summary>
    /// Delete VPP Payments
    /// </summary>
    /// <param name="deliverableIDs">Array of DeliverableIDs to delete</param>
    /// <returns>Number of row affected</returns>
    public static int DeleteVPPPayments(string[] deliverableIDs)
    {
        //Build sql query:
        string query = "DELETE VPPPayment WHERE DeliverableID in (";
        int i;
        for (i = 0; i < deliverableIDs.Length; i++)
        {
            if (i == 0) query += deliverableIDs[i];
            else query += "," + deliverableIDs[i];
        }
        query += ")";
        SqlCommand cmd = DAL.CreateCommand();
        cmd.CommandText = query;
        return DAL.ExecuteNonQuery(cmd);
    }

    /// <summary>
    /// Insert new VPP Payment
    /// </summary>
    /// <param name="deliverableID">DeliverableID of the payment</param>
    /// <param name="amount">Amount of money to collect for customer</param>
    /// <param name="charge">Charge of VPP service</param>
    /// <param name="isCustomerPaid">Define whether money is paid to customer</param>
    /// <returns>Number of row affected</returns>
    public static int InsertVPPPayment(int deliverableID, decimal amount, decimal charge, bool isCustomerPaid)
    {
        SqlCommand cmd = DAL.CreateCommand();
        cmd.CommandText = SQL.InsertVPPPayment;
        cmd.Parameters.AddWithValue("@DeliverableID", deliverableID);
        cmd.Parameters.AddWithValue("@AmountToCollect", amount);
        cmd.Parameters.AddWithValue("@Charge", charge);
        cmd.Parameters.AddWithValue("@IsCustomerPaid", isCustomerPaid);
        return DAL.ExecuteNonQuery(cmd);
    }


    /// <summary>
    /// Update VPP Payment
    /// </summary>
    /// <param name="deliverableID">DeliverableID of the payment</param>
    /// <param name="amount">Amount of money to collect for customer</param>
    /// <param name="charge">Charge of VPP service</param>
    /// <param name="isCustomerPaid">Define whether money is paid to customer</param>
    /// <returns>Number of row affected</returns>
    public static int UpdateVPPPayment(int deliverableID, decimal amount, decimal charge, bool isCustomerPaid)
    {
        SqlCommand cmd = DAL.CreateCommand();
        cmd.CommandText = SQL.UpdateVPPPayment;
        cmd.Parameters.AddWithValue("@DeliverableID", deliverableID);
        cmd.Parameters.AddWithValue("@AmountToCollect", amount);
        cmd.Parameters.AddWithValue("@Charge", charge);
        cmd.Parameters.AddWithValue("@IsCustomerPaid", isCustomerPaid);
        return DAL.ExecuteNonQuery(cmd);
    }
}
